import '../css/style.scss';
import {createewm ,loginStatus,log} from './urlconfig/config.js';
var interval;
var token;
(function (){
    login();
})();
var scene_id;
/*请求二维码*/
function login(){

    $.ajax({
        type:'post',
        url:createewm,
        dataType:'json',
        success:function (res){
            if(res.code === 200){
                settime();
                $(".jihuo-bottom").empty();
                var $login= '<img src="'+ res.data.url + '"   class="login-ewm" ondragstart="return false;">'+
                    '<p>微信扫码登录</p>';
            }
            $(".jihuo-bottom").append($login);
            scene_id =res.data.scene_id;
            if(scene_id !=null){
                status()
            }
        },
        error:function (err){

        }
    })
}

function status(){
    interval = setInterval(function () {
        $.ajax({
            type:'post',
            url:loginStatus,
            dataType:'json',
            data:{
                scene_id:scene_id
            },
            success:function (res){
                if(res.code === 200){
                    token=res.data.token;
                    console.log(token);
                    window.location.href="/pay.html";
                    localStorage.setItem("token",token);
                    clearInterval(interval);
                }

            },
            error:function (err){
                console.log(err)
            }
        })
    },2000)

}
var countdown=1800;
function settime() {
    if (countdown == 0) {
        login();
        countdown = 1800;
    } else {
        countdown--;
        setTimeout(function() {
            settime();
            console.log(countdown)
        },1000)
    }

}
function GetUrlParam(paraName) {
    var url = document.location.toString();
    var arrObj = url.split("?");

    if (arrObj.length > 1) {
        var arrPara = arrObj[1].split("&");
        var arr;

        for (var i = 0; i < arrPara.length; i++) {
            arr = arrPara[i].split("=");

            if (arr != null && arr[0] == paraName) {
                return arr[1];
            }
        }
        return "";
    }
    else {
        return "";
    }
}
var url = document.location.toString();
if (url.indexOf("?") != -1) {
    var edition=GetUrlParam("edition");
    var channel=GetUrlParam("channel");
    var cpuid=GetUrlParam("cpuid");
    var sys=GetUrlParam("sys");
    localStorage.setItem("channel",channel);
    localStorage.setItem("cpuid",cpuid);
    localStorage.setItem("edition",edition);
    localStorage.setItem("sys",sys);
}else{
    localStorage.setItem("channel",'plat_main');
    localStorage.setItem("cpuid",'BFEBFBFF0001067A002100A561EB');
    localStorage.setItem("edition",'WX_1.3.1.1');
    localStorage.setItem("sys",'window10');
}
var main;
if($("#fagepage").length>0){
    main=$("#fagepage").val();
}
$.ajax({
    type:'GET',
    url:log+ main+'/'+ channel+'/'+ edition + '/'+sys+'/'+cpuid,
    dataType: 'json',
    success:function(res) {
        if(res.code==200){
            console.log(res.msg)
        }
    },
    error:function(err) {
        console.log(err)
    }
});


function loginSuccess(){
    $.ajax({
        type:'GET',
        url:log+ 'QrCodeLoginSucceed'+'/'+ channel+'/'+ edition + '/'+sys+'/'+cpuid,
        dataType: 'json',
        success:function(res) {
            if(res.code==200){
                console.log(res.msg)
            }
        },
        error:function(err) {
            console.log(err)
        }
    });
}
import './common.js';